package com.tianji.promotion.controller;


import com.tianji.promotion.domain.dto.CouponDiscountDTO;
import com.tianji.promotion.domain.dto.OrderCourseDTO;
import com.tianji.promotion.service.IUserCouponService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户领取优惠券的记录，是真正使用的优惠券信息 前端控制器
 * </p>
 *
 * @author liuchun
 * @since 2024-10-25
 */
@RestController
@RequestMapping("/user-coupons")
public class UserCouponController {

    @Autowired
    private IUserCouponService userCouponService;

    @ApiOperation("领取发放中的优惠券")
    @PostMapping("/{id}/receive")
    public void receiveCoupon(@PathVariable Long id){
         userCouponService.receiveCoupon(id);
    }

    @ApiOperation("兑换码兑换优惠券")
    @PostMapping("/{code}/exchange")
    public void exchangeCoupon(@PathVariable String code){
         userCouponService.exchangeCoupon(code);
    }

    //查询可用的优惠券
    @PostMapping("/available")
    public List<CouponDiscountDTO> queryDiscountCoupons(@RequestBody List<OrderCourseDTO> orderCourseDTOS){
        return userCouponService.queryDiscountCoupons(orderCourseDTOS);
    }
}
